home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 2: CDPD 1
/
Almathera Ten on Ten - Disc 2: CDPD 1.iso
/
pd
/
101-125
/
118
/
empire
/
src
/
source.zoo
/
messages.d
< prev
next >
Wrap
Text File
|
1987-12-02
|
14KB
|
542 lines
#include:util.g
#empire.g
#empfunc.g
[range(NewsType_t)] ushort NEWS_PAGE = (
3,1,1,2,2,3,3,3,3,2,1,1,2,1,1,2,1,1,1,1,1,3,2,1,1,1,1,1,1,1,1,2,2,1,1,2,1
);
[range(NewsType_t)] short NEWS_GOOD_WILL = (
0, -3, -3, -1, 1, 3, 2, 1, 0, 2, -2, -2, 0, 0, 0, 0, -2, -2, -2,
-3, -1, -2, -1, -4, 0, 0, 5, 0, -5, -5, 5, 0, 0, 0, 0, 0, -2
);
proc cmd_telegram()void:
*char fileName, q;
uint country;
char ch, prevCh, prevPrevCh;
channel input text chin;
file() fyle;
ushort stat;
bool cancel, broadCast;
cancel := false;
broadCast := false;
if InputPtr* = '*' and ThisCountryNumber = DEITY then
InputPtr := InputPtr + 1;
skipBlanks();
broadCast := true;
pretend(FileDestroy(".telegram"), void);
if FileCreate(".telegram") then
if not open(TelegramChannel, fyle, ".telegram") then
err("can't open .telegram for writing");
cancel := true;
fi;
else
err("can't create .telegram");
cancel := true;
fi;
elif not reqCountry(&country, "Country to send telegram to: ") then
cancel := true;
fi;
if not cancel then
if InputPtr* = '\e' then
writeln(Chout; "Enter text of telegram. End with ^\\ or .:");
writeln(Chout;);
if UsingSerial then
open(chin, serialGetChar);
else
open(chin);
fi;
elif UsingSerial then
err("Can't telegram from file when using remote access");
cancel := true;
else
fileName := InputPtr;
skipWord();
q := InputPtr;
skipBlanks();
q* := '\e';
if not open(chin, fyle, fileName) then
writeln(Chout; "*** Can't open file '", fileName, "' ***");
cancel := true;
fi;
fi;
if not cancel then
if not broadCast then
telegramStart(ThisCountryNumber, country);
fi;
while
prevCh := '\e';
ch := '\e';
while
prevPrevCh := prevCh;
prevCh := ch;
read(chin; ch)
do
if ch < ' ' and ch ~= '\t' or ch > '~' then
ch := '?';
fi;
if prevCh ~= '\e' then
write(TelegramChannel; prevCh);
fi;
od;
if prevPrevCh = '\e' and prevCh = '.' then
false
else
if ioerror(chin) = CH_MISSING then
if prevCh ~= '\e' then
write(TelegramChannel; prevCh);
fi;
writeln(TelegramChannel;);
not UsingSerial or not serialHungup()
else
false
fi
fi
do
readln(chin;);
od;
close(chin);
writeln(Chout;);
if broadCast then
close(TelegramChannel);
for country from 0 upto World.w_currCountries - 1 do
writeln(Chout; "Sending telegram to ",
&Country[country].c_name[0]);
if open(chin, fyle, ".telegram") then
telegramStart(ThisCountryNumber, country);
while
while read(chin; ch) do
write(TelegramChannel; ch);
od;
ioerror(chin) = CH_MISSING
do
writeln(TelegramChannel;);
readln(chin;);
od;
telegramEnd();
close(chin);
else
err("Can't open .telegram for reading");
fi;
od;
pretend(FileDestroy(".telegram"), void);
else
telegramEnd();
news(n_sent_telegram, ThisCountryNumber, country);
fi;
fi;
fi;
corp;
/*
* telegramCheck - called to check for new telegrams.
*/
proc telegramCheck()void:
if ThisCountry*.c_telegramsNew ~= 0 then
writeln(Chout; "You have old telegrams.");
fi;
if ThisCountry*.c_telegramsNew ~= ThisCountry*.c_telegramsTail then
writeln(Chout; "You have new telegrams.");
fi;
corp;
proc cmd_read()void:
if ThisCountry*.c_telegramsTail = 0 then
writeln(Chout; "No telegrams");
else
telegramOpen();
while telegramRead(ThisCountry*.c_telegramsTail) do
od;
if ask("Delete these telegrams? ") then
ThisCountry*.c_telegramsNew := 0;
ThisCountry*.c_telegramsTail := 0;
else
ThisCountry*.c_telegramsNew := ThisCountry*.c_telegramsTail;
fi;
fi;
corp;
/*
* sayHeadLine - report on a headline item.
*/
proc sayHeadLine(int recent, past; *char actor, victim)void:
*char message;
message :=
case
if | past > | recent then 1 else 0 fi +
if past >= 0 then 2 else 0 fi +
if recent >= 0 then 4 else 0 fi
incase 0:
"Carnage being wreaked by $ on $ continues unabated!"
incase 1:
if recent < -10 then
"Further $ agression against $"
else
"Peace talks may succeed between $ & $"
fi
incase 2:
if recent < -12 then
if past > 8 then
"! WAR ! A complete reversal of prior $ -- $ relations"
else
if recent < -20 then
"$ wreaks havoc on $!"
else
"VIOLENCE ERUPTS! -- $ wages war on $"
fi
fi
else
"Breakdown in communication between $ & $"
fi
incase 3:
if past > 10 then
"FLASH! $ turns on former ally, $"
else
"$ aggravates rift with $"
fi
incase 4:
if recent > 10 then
"$ enters new era of cooperation with $"
else
"$ \"makes friends\" with $"
fi
incase 5:
if recent > 5 then
"$ willing to bury the hatchet with $"
else
if past < -16 then
"Tensions ease as $ attacks on $ seem at an end"
else
"$ seems to have forgotten earlier disagreement with $"
fi
fi
incase 6:
"$ good deeds further growing alliance with $"
incase 7:
if recent - past < -20 then
"Honeymoon appears to be over between $ & $"
else
"Friendly relations between $ & $ have cooled somewhat"
fi
default:
"***unknown headline***"
esac;
while message* ~= '\e' do
if message* = '$' then
write(Chout; actor);
actor := victim;
else
write(Chout; message*);
fi;
message := message + sizeof(char);
od;
writeln(Chout;);
corp;
/*
* doHeadLines - generate headlines for the given number of days of news.
*/
proc doHeadLines(uint days)void:
type
history_t = struct {
int h_past, h_recent;
};
News_t n;
ulong now, time;
[COUNTRY_MAX, COUNTRY_MAX] history_t hist;
*history_t h;
int goodWill;
uint i, j, scoopI, scoopJ, scoop, day, scoopCount;
bool hadOne;
now := CurrentTime();
writeln(Chout;);
writeln(Chout; " -=[ EMPIRE NEWS ]=-");
writeln(Chout; "::::::::::::::::::::::::::::::::::::::::::::::::::");
writeln(Chout; "! \"All the news that fits, we print.\" !");
writeln(Chout; "::::::::::::::::::::::::::::::::::::::::::::::::::");
write(Chout; " ");
writeDate(now);
writeln(Chout;);
printFile(BULLETIN_FILE);
for i from 0 upto COUNTRY_MAX - 1 do
for j from 0 upto COUNTRY_MAX - 1 do
hist[i, j].h_past := 0;
hist[i, j].h_recent := 0;
od;
od;
time := now - make(days - 1, ulong) * (60 * 60 * 24);
day := 0;
hadOne := false;
while hadOne or day ~= days do
if not hadOne then
if newsOpen(time) then
hadOne := newsNext(n);
else
hadOne := false;
fi;
day := day + 1;
time := time + (60 * 60 * 24);
else
hadOne := newsNext(n);
fi;
if hadOne and n.n_actor ~= n.n_victim then
goodWill := NEWS_GOOD_WILL[n.n_verb];
if goodWill ~= 0 then
h := &hist[n.n_actor, n.n_victim];
if n.n_time - now > days * (60 * 60 * 12) then
h*.h_past := h*.h_past + 1;
else
h*.h_recent := h*.h_recent + 1;
fi;
fi;
fi;
od;
scoopCount := 0;
while
scoop := 9;
for i from 0 upto COUNTRY_MAX - 1 do
for j from 0 upto COUNTRY_MAX - 1 do
h := &hist[i, j];
goodWill := | h*.h_recent / 2;
if make(goodWill, uint) > scoop then
scoop := goodWill;
scoopI := i;
scoopJ := j;
fi;
goodWill := | (h*.h_recent - h*.h_past);
if make(goodWill, uint) > scoop then
scoop := goodWill;
scoopI := i;
scoopJ := j;
fi;
od;
od;
writeln(Chout;);
scoop > 9 and scoopCount < 5
do
scoopCount := scoopCount + 1;
h := &hist[scoopI, scoopJ];
sayHeadLine(h*.h_recent, h*.h_past,
&Country[scoopI].c_name[0], &Country[scoopJ].c_name[0]);
h*.h_recent := 0;
h*.h_past := 0;
h := &hist[scoopJ, scoopI];
goodWill := h*.h_recent - h*.h_past;
if goodWill <= -make(scoop / 2, int) or
goodWill >= make(scoop / 2, int) then
writeln(Chout;
case goodWill % 4
incase 0:
" Meanwhile"
incase 1:
" On the other hand"
incase 2:
" At the same time"
incase 3:
" Although"
esac);
sayHeadLine(h*.h_recent, h*.h_past,
&Country[scoopJ].c_name[0],
&Country[scoopI].c_name[0]);
h*.h_recent := 0;
h*.h_past := 0;
fi;
od;
if scoopCount = 0 then
writeln(Chout; "Relative calm prevails.");
fi;
corp;
proc cmd_headlines()void:
int i;
if InputPtr* = '\e' then
doHeadLines(1);
elif getNumber(&i) and i > 0 then
doHeadLines(i);
else
err("invalid day count");
fi;
corp;
/*
* sayNews - report an item of news, and how many times it happened.
*/
proc sayNews(NewsType_t verb; ushort actor, victim; ulong time;uint count)void:
*char v;
writeDate(time);
write(Chout; ": ", &Country[actor].c_name[0], ' ');
v := &Country[victim].c_name[0];
case verb
incase n_nothing:
write(Chout; "did nothing in particular to ", v);
incase n_won_sector:
write(Chout; "won a sector from ", v);
incase n_lost_sector:
write(Chout; "was repulsed by ", v);
incase n_spy_shot:
write(Chout; "had a spy shot by ", v);
incase n_sent_telegram:
write(Chout; "sent a telegram to ", v);
incase n_sign_treaty:
write(Chout; "signed a treaty with ", v);
incase n_make_loan:
write(Chout; "made a loan to ", v);
incase n_repay_loan:
write(Chout; "repaid a loan from ", v);
incase n_make_sale:
write(Chout; "made a sale to ", v);
incase n_grant_sector:
write(Chout; "granted land to ", v);
incase n_shell_sector:
write(Chout; "shelled land owned by ", v);
incase n_shell_ship:
write(Chout; "shelled a ship owned by ", v);
incase n_took_unoccupied:
write(Chout; "took over unoccupied land");
incase n_torp_ship:
write(Chout; "had a ship torpedoed");
incase n_fire_back:
write(Chout; "fired on ", v, " in self defense");
incase n_broke_sanctuary:
write(Chout; "broke sanctuary");
incase n_bomb_sector:
write(Chout; "bombed one of ", v, "'s sectors");
incase n_bomb_ship:
write(Chout; "bombed a ship flying the flag of ", v);
incase n_board_ship:
write(Chout; "boarded a(n) ", v, " ship");
incase n_failed_board:
write(Chout; "was repelled by ", v,
" while attempting to board a ship");
incase n_flak:
write(Chout; "fired on ", v, " aircraft");
incase n_sieze_sector:
write(Chout; "siezed a sector from ", v,
" in collecting on a loan");
incase n_honor_treaty:
write(Chout;
"considered an action which would have violated a treaty with",
v);
incase n_violate_treaty:
write(Chout; "violated a treaty with ", v);
incase n_dissolve:
write(Chout; "dissolved its government");
incase n_hit_mine:
write(Chout; "ship hit a mine");
incase n_decl_ally:
write(Chout; "announced an alliance with ", v);
incase n_decl_neut:
write(Chout; "declared their neutrality toward ", v);
incase n_decl_war:
write(Chout; "declared WAR on ", v);
incase n_disavow_ally:
write(Chout; "disavowed former alliance with ", v);
incase n_disavow_war:
write(Chout; "disavowed former war with ", v);
incase n_storm_sector:
write(Chout; "sector damaged by hurricane");
incase n_storm_ship:
write(Chout; "navy sufferred hurricane damages");
incase n_plague_outbreak:
write(Chout; "reports outbreak of PLAGUE");
incase n_plague_die:
write(Chout; "citizens killed by PLAGUE");
incase n_name_change:
write(Chout; "went through a name change");
incase n_drop_sub:
write(Chout; "depth charged a(n) ", v, " submarine");
default:
write(Chout; "***unknown news type***");
esac;
if count ~= 1 then
write(Chout; ' ', count, " times");
fi;
writeln(Chout;);
corp;
proc cmd_newspaper()void:
News_t n;
ulong now, start, time, prevTime;
int i;
uint days, page, day, count;
NewsType_t prevVerb;
ushort prevActor, prevVictim;
bool quit, hadOne;
quit := false;
if InputPtr* = '\e' then
days := 1;
elif getNumber(&i) and i > 0 then
days := i;
else
err("invalid day count");
quit := true;
fi;
if not quit then
doHeadLines(days);
now := CurrentTime() / (60 * 60 * 24) * (60 * 60 * 24);
start := now - make(days - 1, ulong) * (60 * 60 * 24);
writeln(Chout;);
write(Chout; "The details of Empire news since ");
writeDate(start);
writeln(Chout;);
for page from 1 upto 3 do
writeln(Chout;);
writeln(Chout; " === page ", page, " ===");
prevVerb := n_nothing;
prevActor := DEITY;
prevVictim := DEITY;
count := 0;
time := start;
day := 0;
hadOne := false;
while hadOne or day ~= days do
if not hadOne then
if newsOpen(time) then
hadOne := newsNext(n);
else
hadOne := false;
fi;
day := day + 1;
time := time + (60 * 60 * 24);
else
hadOne := newsNext(n);
fi;
if hadOne then
if NEWS_PAGE[n.n_verb] = page then
if n.n_verb ~= prevVerb or n.n_actor ~= prevActor or
n.n_victim ~= prevVictim then
if count ~= 0 then
sayNews(prevVerb, prevActor, prevVictim,
prevTime, count);
fi;
count := 1;
prevVerb := n.n_verb;
prevActor := n.n_actor;
prevVictim := n.n_victim;
prevTime := n.n_time;
else
count := count + 1;
fi;
fi;
fi;
od;
if count ~= 0 then
sayNews(prevVerb, prevActor, prevVictim, prevTime, count);
fi;
od;
writeln(Chout;);
fi;
corp;